var e = require("../../requests/request.js"), t = (require("../../utils/util.js"), 
getApp());

Page({
    data: {
        openid: "",
        carlist: [],
        ischeckall: !1,
        isedit: !1,
        carcollect: t.globalData.carcollect,
        isrepeat: !1
    },
    onLoad: function(a) {
        wx.showNavigationBarLoading(), console.log("----onLoad");
        var o = this;
        console.log("----全局缓存车型收藏："), console.log(o.data.carcollect), o.setData({
            openid: wx.getStorageSync("opid")
        }), console.log(" that.data.openid=" + o.data.openid), e.getcarCollectlist(o.data.openid, 1, function(e) {
            if (console.log("---getcarCollectlist"), console.log(e), 1 == e.statusCode) {
                var a = e.data.list, l = o.data.carcollect;
                l || (l = []);
                for (var c = !1, s = 0; s < a.length; s++) a[s].ischecked = !1, a[s].Image = a[s].Image.replace("{0}", "3"), 
                l.indexOf(a[s].SerialId) < 0 && (l.push(a[s].SerialId), c = !0);
                c && (t.globalData.carcollect = l, console.log("已更新到全局变量")), o.setData({
                    carlist: a
                }), console.log(a), console.log(l);
            }
        }, function(e) {
            o.setmsg("提交失败，请稍后再试"), console.log(e);
        }, function(e) {
            console.log(e), wx.hideNavigationBarLoading();
        });
    },
    onReady: function() {},
    startEdit: function(e) {
        this.setData({
            isedit: !0
        });
    },
    clickcancelEdit: function(e) {
        this.setData({
            isedit: !1,
            ischeckall: !1
        });
        for (var t = this.data.carlist, a = 0; a < t.length; a++) t[a].ischecked && (t[a].ischecked = !1);
        this.setData({
            carlist: t
        });
    },
    checkItem: function(e) {
        console.log("----check item"), console.log(e);
        var t = e.currentTarget.dataset.row;
        console.log("select index=" + t);
        var a = this, o = a.data.carlist;
        o[t].ischecked = !o[t].ischecked, a.setData({
            carlist: o
        });
    },
    clickGotoSummary: function(e) {
        var t = this, a = e.currentTarget.dataset.serialid, o = e.currentTarget.dataset.serialname;
        t.data.isedit ? console.log("编辑状态不跳转车型：" + a) : (console.log("您将跳转到车型：" + a), wx.navigateTo({
            url: "../summary/summary?id=" + a + "&name=" + o
        }));
    },
    checkAll: function() {
        for (var e = this, t = e.data.carlist, a = !e.data.ischeckall, o = 0; o < t.length; o++) t[o].ischecked = a;
        e.setData({
            carlist: t,
            ischeckall: a
        });
    },
    deleteMore: function() {
        var a = this;
        if (a.data.isrepeat) return a.setmsg("请不要重复操作"), void console.log("请不要重复操作");
        a.setData({
            isrepeat: !0
        });
        for (var o = [], l = a.data.carlist, c = "", s = 0; s < l.length; s++) l[s].ischecked ? c += l[s].SerialId + "," : o.push(l[s]);
        if (c.length > 1 && (c = c.substr(0, c.length - 1)), console.log("您所选择的车型：" + c), 
        c.length < 1) return a.setData({
            isrepeat: !1
        }), a.setmsg("您未选择任何车型"), void console.log(o);
        e.deletemorecarCollect(a.data.openid, c, function(e) {
            if (console.log("---deletecarCollect 请求结束，返回数据："), console.log(e), 1 == e.statusCode) {
                a.data.carcollect = [];
                for (var l = 0; l < o.length; l++) a.data.carcollect.push(o[l].SerialId);
                a.setData({
                    carlist: o,
                    carcollect: a.data.carcollect
                }), (null == o || o.length < 1) && a.setData({
                    isedit: !1
                }), t.globalData.carcollect = a.data.carcollect, console.log("-----删除成功，最新列表数据："), 
                console.log(o), console.log(a.data.carcollect), a.setmsg("删除成功！");
            } else a.setmsg(e.message);
        }, function(e) {
            a.setmsg("系统繁忙，请稍后再试"), console.log("deletecarCollect-error");
        }, function(e) {
            console.log("deletecarCollect--complete"), a.setData({
                isrepeat: !1
            });
        });
    },
    setmsg: function(e) {
        wx.showToast({
            title: e,
            icon: "none"
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});